from API.btc126 import get_btc126_usdtcny_premium
import os
import pandas as pd
from utils import df_into_db


print('更新btc126上的usdt兑cny溢价')
DATA_DIR = 'E:\\data'
PREMIUM_DATA_DIR = os.path.join(DATA_DIR, 'usdt_premium')
file_name = os.path.join(PREMIUM_DATA_DIR, 'usdtcny_premium_btc126.csv')
update = get_btc126_usdtcny_premium()
if os.path.exists(file_name):
    historical_df = pd.read_csv(file_name)
    df = pd.concat([historical_df, update], axis=0, ignore_index=True)
    df.drop_duplicates(subset=['atime'], keep='first', inplace=True)
    df.rename(columns={'id': 'tid'}, inplace=True)
    # df.to_csv(file_name, index=False)
    df_into_db(df, db_name="usdt_premium", table_name="usdtcny_premium_btc126")
    pass
else:
    # update.to_csv(file_name, index=False)
    pass